<template>
	<view>
		<view class="GoodNav" v-for="(item,index) in Goodlists" :key="index">
			<good-list :goods="item" @Myclick="to_detail(item)"></good-list>
		</view>
		<view v-if="Goodlists.length===0">暂无数据</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryObj: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 10
				},
				Goodlists: [],
				total: null

			}
		},
		methods: {
			// 获取列表
			async getGoodsList(callback) {
				let {
					data: res
				} = await uni.$http.get('/goods/search', this.queryObj)
				callback && callback()
				if (res.meta.status !== 200) return uni.$showMsg()
				this.Goodlists = [...this.Goodlists, ...res.message.goods]
				this.total = res.message.total
				
			},
			to_detail(goods) {
				uni.navigateTo({
					url: '../goods_detail/goods_detail?goods_id=' + goods.goods_id
				})
			}
		},
		onLoad(option) {
			this.queryObj.query = option.query || ""
			this.queryObj.cid = option.cid || ""
			this.getGoodsList()

		},
		onReachBottom() {
			if (this.queryObj.pagesize * this.queryObj.pagenum >= this.total) return uni.$showMsg("没有更多数据了")
			this.queryObj.pagenum = this.queryObj.pagenum + 1
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.queryObj.pagenum = 1
			this.total = 0
			this.isloading = false
			this.goodsList = []
			this.getGoodsList(()=>{uni.stopPullDownRefresh()})
		}


	}
</script>

<style scoped>
	.GoodNav {
		/* display: flex; */
		padding: 20rpx 10rpx;
		border-bottom: 1px solid rgba(0, 0, 0, 0.2);
	}
</style>
